package com.xiaoshuidi.cloud.module.rooms.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.map.vo.GetHFAdministrative;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.map.vo.RoomStreetLatlonResp;
import com.xiaoshuidi.cloud.module.rooms.framework.config.ConfigValues;
import com.xiaoshuidi.cloud.module.rooms.pojo.RoomStreetLatlon;
import com.xiaoshuidi.cloud.module.rooms.mapper.RoomStreetLatlonMapper;
import com.xiaoshuidi.cloud.module.rooms.repository.RoomStreetLatlonRepository;
import com.xiaoshuidi.cloud.module.rooms.service.RoomStreetLatlonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 区域街道经纬度 服务实现类
 * </p>
 *
 * @author hans.zhang
 * @since 2023-05-21
 */
@Service
public class RoomStreetLatlonServiceImpl extends ServiceImpl<RoomStreetLatlonMapper, RoomStreetLatlon> implements RoomStreetLatlonService {

    @Resource
    private RoomStreetLatlonRepository roomStreetLatlonRepository;
    @Resource
    private ConfigValues configValues;

    /**
     * 获取合肥行政区域
     * @return
     */
    @Override
    public List<GetHFAdministrative> getHFAdministrative() {
//        LambdaQueryWrapper<RoomStreetLatlon> wrapper = Wrappers.lambdaQuery();
//        wrapper.eq(RoomStreetLatlon::getLevel, 3);
//        List<RoomStreetLatlon> parents = roomStreetLatlonRepository.list(wrapper);
        List<RoomStreetLatlonResp> parents = roomStreetLatlonRepository.getRoomStreetLatlon();
        List<GetHFAdministrative> resp = new ArrayList<>();
        for (RoomStreetLatlonResp roomStreetLatlonResp : parents) {
            GetHFAdministrative getHFAdministrative = new GetHFAdministrative();
            getHFAdministrative.setParent(roomStreetLatlonResp);
            LambdaQueryWrapper<RoomStreetLatlon> wrapper2 = Wrappers.lambdaQuery();
            wrapper2.eq(RoomStreetLatlon::getLevel, 4);
            wrapper2.eq(RoomStreetLatlon::getPid, roomStreetLatlonResp.getId());
            List<RoomStreetLatlon> nodes = roomStreetLatlonRepository.list(wrapper2);
            getHFAdministrative.setNodes(nodes);
            resp.add(getHFAdministrative);
        }
        return resp;
    }
}
